package com.zhangtai.modules.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhangtai.modules.dto.DimissionInfoDto;
import com.zhangtai.modules.entity.employee.DimissionAuditEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 离任审计通知
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-09-02 09:47:33
 */
@Mapper
public interface DimissionAuditDao extends BaseMapper<DimissionAuditEntity> {

    @Select(
            "<script>" +
                    "Select audit.*,info.`code`,info.`name`,\n" +
                    "\tinfo.jobname,\n" +
                    "\tinfo.job_level_id,\n" +
                    "\tinfo.job_level,\n" +
                    "\tinfo.job_level_type,\n" +
                    "\tinfo.orgname,\n" +
                    "\tinfo.unitname,\n" +
                    "\tinfo.job_system,\n" +
                    "\tinfo.line,\n" +
                    "\tinfo.hiredate,\n" +
                    "\tinfo.dimission_time,\n" +
                    "\tinfo.working_years,\n" +
                    "\tinfo. MODE,\n" +
                    "\tinfo.dimission_type,\n" +
                    "\tinfo.apply_oid,\n" +
                    "\tinfo.apply_code,\n" +
                    "\tinfo.apply_name,\n" +
                    "\tinfo.apply_time,\n" +
                    "\tinfo.apply_dep_id,\n" +
                    "\tinfo.apply_department from tb_dimission_audit audit  " +
                    "left join tb_dimission_info info  on info.id = audit.dimission_id  " +
                    "<where>" +
                    "<if test='name!=null'> and info.name = '%${name}%' </if>" +
                    "<if test='code!=null'> and info.code = '%${code}%' </if>" +
                    "<if test='hiredateStart!=null'> and info.hiredate >= #{hiredateStart} </if>" +
                    "<if test='hiredateEnd!=null'> and info.hiredate >= #{hiredateEnd} </if>" +
                    "<if test='status!=null'> and audit.status = #{status} </if>" +
                    "<if test='upcomingStatus!=null'> and audit.upcomingStatus = #{upcomingStatus} </if>" +

                    "<if test='jobLevelId!=null'> and info.job_level_id = #{jobLevelId} </if>" +
                    "<if test='lineId!=null'> and info.line_id = #{lineId} </if>" +
                    "<if test='jobSystemId!=null'> and info.job_system_id = #{jobSystemId} </if>" +
                    " and audit.is_delete = '0' " +
                    "</where>  order by audit.create_time desc" +
                    "</script>"
    )
    List<Map<String,Object>> getAuditList(
            @Param(value = "name") String name,
            @Param(value = "code") String code,
            @Param(value = "hiredateStart") String hiredateStart,
            @Param(value = "hiredateEnd") String hiredateEnd,
            @Param(value = "jobLevelId") Long jobLevelId, //职级id
            @Param(value = "status") Integer status, //审批状态
            @Param(value = "upcomingStatus") Integer upcomingStatus, //审计待办状态
            @Param(value = "lineId") Long lineId, //专业职级id
            @Param(value = "jobSystemId") Long jobSystemId, //专业职级id
            Page<DimissionInfoDto> page
    );

}
